<%@ page contentType="text/html; charset=UTF-8"%>
<%@include file="/html/portlet/chart/view/init.jsp"%>

<portlet:defineObjects />
<%
Option selOption = null;
String chart_height="400px";
try{
	if(Validator.isNotNull(chart_view_optionid)){
		selOption = OptionLocalServiceUtil.getOption(chart_view_optionid);
	}
	if(Validator.isNotNull(chart_view_height)){
		chart_height=chart_view_height+chart_view_height_unit;
	}
%>
<c:choose>
	<c:when test="<%= (selOption != null) %>">
		<div id='<portlet:namespace/>chart_view_portlet_main' >
		</div>
		<portlet:resourceURL var="getchartdata" id="getchartdata"></portlet:resourceURL>
		<aui:script use="aui-base,aui-io-request">
			var chart_view=A.one('#<portlet:namespace/>chart_view_portlet_main');
			A.io.request('${getchartdata}', {
				dataType : 'html',
				data: {
			     	<portlet:namespace />optionId: '<%=selOption.getOptionId() %>',
			     	<portlet:namespace />namespace: '<portlet:namespace />',
			     	<portlet:namespace />chart_view_theme: '<%=chart_view_theme %>',
			     	<portlet:namespace />chart_height:'<%=chart_height %>'
			   	},
			   	on:{
			   		success: function() {
			   			chart_view.html(this.get('responseData'));
			   			analysis_js(this.get('responseData'));
			   		}
			   	}
			}); 
		</aui:script>
	</c:when>
	<c:otherwise>
			<div class="alert alert-info">
				<liferay-ui:message key="chart.view.select.existing.option" />
			</div>
		</c:otherwise>
</c:choose>
<% 
}
catch (NoSuchOptionException nsrse) {
%>
	<div class="alert alert-error">
		<liferay-ui:message key="chart.view.selected.option.no.longer.exists" />
	</div>
<%
}
boolean hasConfigurationPermission = PortletPermissionUtil.contains(permissionChecker, layout, portletDisplay.getId(), ActionKeys.CONFIGURATION);
%>
<c:if test="<%= themeDisplay.isSignedIn() && !layout.isLayoutPrototypeLinkActive() && (hasConfigurationPermission ) %>">
	<div class="lfr-meta-actions icons-container">
		<div class="lfr-icon-actions">
			<liferay-ui:icon
					cssClass="lfr-icon-action lfr-icon-action-configuration"
					image="configuration"
					label="<%= true %>"
					message="chart.view.select.chart.option"
					method="get"
					onClick="<%= portletDisplay.getURLConfigurationJS() %>"
					url="<%= portletDisplay.getURLConfiguration() %>"
				/>
		</div>
	</div>
</c:if>
